package org.seedltd.upms.controller.sys;

import org.seedltd.core.base.BaseController;
import org.seedltd.core.base.BasePage;
import org.seedltd.core.utils.Assert;
import org.seedltd.core.validation.Save;
import org.seedltd.core.validation.Update;
import org.seedltd.log.annotation.SysLog;
import org.seedltd.upms.model.sys.form.SysDictTypeForm;
import org.seedltd.upms.model.sys.form.SysDictTypeSearchForm;
import org.seedltd.upms.model.sys.vo.SysDictTypeVO;
import org.seedltd.upms.service.sys.SysDictTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;

/**
 *
 * 字典类型控制器
 * 
 * @author laizuan
 * @version 1.0
 * @since 2021/09/01
 */
@RestController
@AllArgsConstructor
@RequestMapping("/sysDictType")
public class SysDictTypeController extends BaseController<SysDictTypeService> {

    /**
     * 新增
     * 
     * @param form
     *            字典类型表单数据
     * @return 字典类型主键
     */
    @SysLog("新增字典类型")
    @PostMapping(value = "/add")
    @PreAuthorize("hasAuthority('sys:dictType:add')")
    public Long add(@RequestBody @Validated({Save.class}) SysDictTypeForm form) {
        return baseService.add(form);
    }

    /**
     * 获取详情
     * 
     * @param id
     *            字典类型主键
     * @return 字典类型
     */
    @GetMapping(value = "/get")
    public SysDictTypeVO get(Long id) {
        Assert.notNull(id, "参数不能为空");
        return baseService.findById(id);
    }

    /**
     * 修改
     * 
     * @param form
     *            字典类型表单数据
     * @return 修改状态。true标识修改成功，false标识修改失败
     */
    @SysLog("修改字典类型")
    @PostMapping(value = "/update")
    @PreAuthorize("hasAuthority('sys:dictType:update')")
    public boolean update(@RequestBody @Validated({Update.class, Save.class}) SysDictTypeForm form) {
        return baseService.update(form);
    }

    /**
     * 删除
     * 
     * @param id
     *            字典类型主键
     * @return 删除状态。true标识修改成功，false标识修改失败
     */
    @SysLog("删除字典类型")
    @GetMapping(value = "/delete")
    @PreAuthorize("hasAuthority('sys:dictType:delete')")
    public boolean delete(Long id) {
        Assert.notNull(id, "ID不能为空");
        return baseService.delete(id);
    }

    /**
     * 列表
     * 
     * @param searchForm
     *            查询条件
     * @return 字典类型列表集合
     */
    @PostMapping(value = "/list")
    public BasePage<SysDictTypeVO> page(@RequestBody SysDictTypeSearchForm searchForm) {
        return baseService.page(searchForm);
    }

}